package com.demo.orders;

import com.demo.common.model.Orders;
import com.jfinal.core.Controller;
import com.jfinal.validate.Validator;

public class OrdersValidator extends Validator {

    @Override
    protected void validate(Controller controller) {
        validateRequiredString("orders.studentid", "studentidMsg", "请输入学生学号!");
        validateRequiredString("orders.bookid", "bookidMsg", "请输入图书索书号!");
        validateRequiredString("orders.ordertime", "ordertimeMsg", "请输入预约时间!");
    }

    @Override
    protected void handleError(Controller controller) {
        controller.keepModel(Orders.class);

        String actionKey = getActionKey();
        if (actionKey.equals("/orders/save"))
            controller.render("add.html");
        else if (actionKey.equals("/orders/update"))
            controller.render("edit.html");
    }
}
